package com.boarsoft.boar.flow.monitor;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FlowMonitorConfig {
	private static final Logger log = LoggerFactory.getLogger(FlowMonitorConfig.class);
	private static Properties prop;
	//
	public static String APP_ENV = "DEV";

	static {
		if (prop == null) {
			InputStream is = FlowMonitorConfig.class.getClassLoader()
					.getResourceAsStream("conf/config.properties");
			if (is == null) {
				log.warn("Can not init {}/config.properties", FlowMonitorConfig.class.getName());
			} else {
				log.info("Init AgentConfig with default config.properties");
				FlowMonitorConfig.init(is);
			}
		}
	}

	public static void init(InputStream is) {
		if (prop == null) {
			prop = new Properties();
			try {
				prop.load(is);

				APP_ENV = prop.getProperty("app.env", APP_ENV);
			} catch (IOException e) {
				log.error("Error on load system config.", e);
				throw new RuntimeException(e);
			}
		}
	}

	public static String getProperty(String name) {
		return prop.getProperty(name);
	}

}